import cv2
import numpy as np

img = cv2.imread('img/landscape.png')
# 原尺寸
h, w, c = img.shape
print(img.shape)
# 放大倍数
factor = 0.5
# 新尺寸
h_new = round(h * factor)
w_new = round(w * factor)
# 创建新图像
new_img = np.zeros((h_new, w_new, 3), dtype=np.uint8)
# 循环对新图像赋值
for i in range(h_new):
    for j in range(w_new):
        # 新尺寸乘以系数，映射到原图的(x, y), 再四舍五入取整。
        # 算出来的值可能大于等于原现状，用min限制一下
        new_i = min(round(i/factor), h-1)
        new_j = min(round(j/factor), w-1)
        new_img[i, j] = img[new_i, new_j]

cv2.imshow('', new_img)
cv2.waitKey(0)
